package com.song.exception.controller;

import com.song.pojo.Emp;
import com.song.pojo.EmpQueryParam;
import com.song.pojo.Result;
import com.song.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService EmpService;

//    @GetMapping
////    public Result Emplist(@RequestParam(defaultValue = "1") Integer page,
////                          @RequestParam(defaultValue = "10") Integer size,
////                          String name,
////                          Integer gender,
////                          @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
////                          @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
////        log.info("查询所有员工信息");
////        log.info("page={},size={},name={},gender={},startData={},endData={}",page,size, name,gender,startDate,endDate);
////        return Result.success(EmpService.pagelist(page,size,name,gender,startDate,endDate));
////    }
    @GetMapping
    public Result Emplist(EmpQueryParam  param) {
        System.out.println(param);
        return Result.success(EmpService.pagelist(param));
    }

    @PostMapping
    public Result addEmp(@RequestBody Emp emp) throws Exception {
        log.info("添加员工信息");
        log.info("emp={}",emp);
        EmpService.addEmp(emp);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteEmp(@RequestParam List<Integer> ids) {
        log.info("删除员工信息");
        log.info("ids={}",ids);
        EmpService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        Emp emp = EmpService.findById(id);
        return Result.success(emp);
    }

    @PutMapping
    public Result updateEmp(@RequestBody Emp emp) {
        log.info("修改员工信息");
        log.info("emp={}",emp);
        EmpService.updateEmp(emp);
        return Result.success();
    }

}














































































































































































































































































































































































































































































































































































































































































































































































































































































































